<div class="layuimini-container layuimini-page-anim">
        <div class="layuimini-main">
        <fieldset class="table-search-fieldset layui-hide">
            <legend>搜索信息</legend>
            <form class="layui-form layui-form-pane" action="">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">用户姓名</label>
                        <div class="layui-input-inline">
                            <input type="text" name="username" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button type="submit" class="layui-btn layui-btn-primary" lay-submit
                                lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索
                        </button>
                    </div>
                </div>
            </form>
        </fieldset>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <{if AdminUsersModel::check_right("$module/$controller/save")}>
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add">添加</button>
                <{/if}>
            </div>
        </script>

        <table class="layui-hide" id="table-page" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="table-action">
            <{if AdminUsersModel::check_right("$module/$controller/save")}>
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
            <{/if}>
            <{if AdminUsersModel::check_right("$module/$controller/del")}>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="del">删除</a>
            <{/if}>
        </script>
    </div>
</div>
<script type="text/javascript">
    layui.use(['form', 'table', 'miniPage', 'element'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            miniPage = layui.miniPage;

        table.render({
            elem: '#table-page',
            url: '/<{$module}>/<{$controller}>/index?do=list',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports'],
            height: 'full-150',//一行条件
            page: true,
            cols: [[
                {field: 'id', width: 60, title: 'ID'}
                , {field: 'gname', width: 180, title: '角色名称'}
                , {align: 'left', fixed: 'right', toolbar: '#table-action'}
            ]]
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            //执行搜索重载
            table.reload('admin_role_indx', {
                page: {
                    curr: 1
                }
                , where: {
                    searchParams: result
                }
            }, 'data');
            return false;
        });
        /**
         * toolbar事件监听
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            var type = obj.event;
            active[type] ? active[type].call(this, obj) : '';
        });
        table.on('tool(currentTableFilter)', function (obj) {
            var type = obj.event;
            active[type] ? active[type].call(this, obj) : '';
        });

        var active = {
            edit: function (obj) { //获取选中数据
                var data = obj.data;
                var content = miniPage.getHrefContent('/<{$module}>/<{$controller}>/save/gid/' + data.id);
                var index = layer.open({
                    title: '编辑'
                    , type: 1
                    , shade: 0.5
                    , maxmin: true
                    , area: ['60%', '90%']
                    , shadeClose: true
                    , content: content
                    , btn: ['确定', '取消']
                    , yes: function (index, layero) {
                        layero.find("#form-submit").click();
                    }
                    , success: function (layero, index) {
                        console.log(layero, index);
                    }
                });
            }
            , del: function (obj) {
                var data = obj.data;
                layer.confirm('确定需要删除此角色分组吗?', function (index) {
                    $.post('/<{$module}>/<{$controller}>/del/gid/' + data.id + '?isajax=1&', {}, function (res) {
                        layer.msg(res.msg);
                    }, 'json');
                    table.reload('table-page');
                });
            }
            , add: function () {
                var content = miniPage.getHrefContent('/<{$module}>/<{$controller}>/save');
                var index = layer.open({
                    title: '添加'
                    , type: 1
                    , shade: 0.5
                    , maxmin: true
                    , area: ['60%', '90%']
                    , shadeClose: true
                    , content: content
                    , btn: ['确定', '取消']
                    , yes: function (index, layero) {
                        layero.find("#form-submit").click();
                    }
                });
            }
        };
    });
</script>